package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 护理项目Service实现类
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 分页查询护理项目列表
     * @param name 项目名称
     * @param status 项目状态
     * @param pageNum 当前页码
     * @param pageSize 每页显示数量
     * @return PageResponse<NursingProjectVo>
     */
    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer pageNum, Integer pageSize, Integer status ) {
        //使用分页插件分页
        PageHelper.startPage(pageNum, pageSize);

        //调用Mapper条件查询
        Page<NursingProjectVo> page = nursingProjectMapper.getPage(name, status);

        //分页查询的数据保存到PageResponse对象中
        PageResponse<NursingProjectVo> pageResponse = new PageResponse(page);
        pageResponse.setRecords(page.getResult());

        return pageResponse;
    }

    /**
     * 新增护理项目
     * @param nursingProjectDTO 护理项目数据传输对象
     */
    @Override
    public void add(NursingProjectDto nursingProjectDTO) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDTO, nursingProject);
        nursingProjectMapper.insert(nursingProject);
    }


    /**
     * 根据ID查询护理项目
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo getById(Long id) {
        NursingProject nursingProject = nursingProjectMapper.selectById(id);
        return BeanUtil.toBean(nursingProject,NursingProjectVo.class);
    }

    /**
     * 更新护理项目信息
     *
     * @param nursingProjectDTO 护理项目数据传输对象
     */
    @Override
    public void update(NursingProjectDto nursingProjectDTO) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDTO, nursingProject);
        nursingProjectMapper.update(nursingProject);
    }

    /**
     * 删除护理项目
     * @param id
     */
    @Override
    public void delete(Long id) {
        nursingProjectMapper.deleteById(id);
    }

    /**
     * 更改护理项目状态
     * @param id
     * @param status
     */
    @Override
    public void changeStatus(Long id, Integer status) {
        nursingProjectMapper.changeStatus(id,status);
    }

    /**
     * 查询所有护理项目
     * @return
     */
    public List<NursingProjectVo> getAll(NursingProject nursingProject) {
        List<NursingProjectVo> nursingProjectVos = nursingProjectMapper.getAll(nursingProject);
        return nursingProjectVos;
    }





}